package com.c.ctgproject.ui.collect

import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.c.ctgproject.adapter.ImageCommonRvV2Adapter
import com.c.ctgproject.adapter.guang.BatteryImageAdapter
import com.c.ctgproject.adapter.guang.HandlerBatteryDetailAdapter
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityHandlerBatteryDetailBinding
import com.c.ctgproject.entity.guang.HandlerBatteryDetailEntityV2
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MyObserverHandlerLoading
import com.c.ctgproject.utils.*
import com.c.ctgproject.wiget.common.CarInfoLayout

/**
 *作者:LiBW
 *创建日期: 2021/9/17
 *描述: 电池拆解单详情 页面 电池详情 页面
 */
class HandlerBatteryDetailActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityHandlerBatteryDetailBinding.inflate(layoutInflater) }
    override fun getLayout() = mBinding.root

    //    private val pbDismantleId by lazy { intent.getIntExtra(MyConstants.PB_DISMANTLE_ID, -1) }
    private val pbId by lazy { intent.getIntExtra(MyConstants.PB_ID, -1) }

    override fun event() {
//        mBinding.mPreTV.visibility = View.GONE
//        mBinding.mInTV.visibility = View.GONE
//        mBinding.mHandlerTV.visibility = View.GONE
//        mBinding.mBatteryHandlerTV.visibility = View.GONE
//        mBinding.mBatterySecondTV.visibility = View.GONE
//        mBinding.mBatterySanTV.visibility = View.GONE

        ApiMethods.apiSubscribe(ApiMethods.retrofit.handleBatteryDetailV2(pbId), MyObserverHandlerLoading(this, loading) {
            MyLog.d("电池拆解单详情回调:$it")
            val data = getGson().fromJson(it, HandlerBatteryDetailEntityV2::class.java).data
            data?.let { bean ->
                mBinding.mContainer1.addView(CarInfoLayout(this, "电池拆解单号", bean.pbDismantleNo.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "开单人", bean.createPersonName.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "开单时间", bean.createTime.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "计划完成时间", bean.plainFinishTime.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "实际完成时间", bean.realFinishTime.noDataHandler()))

                val data2 = bean
                mBinding.moduleCount.text = data2.moduleCount.noDataHandler()
                mBinding.batteryName.text = data2.batteryName.noDataHandler()
                mBinding.batteryCode.text = data2.batteryCode.noDataHandler()
                mBinding.batterySelfCode.text = data2.batterySelfCode.noDataHandler()
                mBinding.carCode.text = data2.carCode.noDataHandler()
                mBinding.count.text = data2.count.noDataHandler()
                mBinding.weight.text = data2.weight.noDataHandler()
                mBinding.capacityAh.text = data2.capacityAh.noDataHandler()
                mBinding.capacityKwh.text = data2.capacityKwh.noDataHandler()
                mBinding.voltage.text = data2.voltage.noDataHandler()
                mBinding.remark.text = data2.remark.noDataHandler()
                mBinding.stockPosi.text=data2.stockPosi.noDataHandler()
                val status = when (data2.status) {
                    1 -> "待入库"
                    2 -> "已拆解"
                    3 -> "已出库"
                    4 -> "拆解中"
                    else -> "暂无数据"
                }
                mBinding.status.text = status
                val enterMode = when (data2.enterMode) {
                    1 -> "整车电池"
                    2 -> "散件"
                    3 -> "电池拆解"
                    else -> "暂无数据"
                }
                mBinding.enterMode.text = enterMode

                val batteryType = when (data2.batteryType) {
                    1 -> "电池包"
                    2 -> "模组"
                    3 -> "电芯"
                    else -> "暂无数据"
                }
                mBinding.batteryType.text = batteryType
                mBinding.mNewBattery.visibility = if (data2.child == null) View.GONE else View.VISIBLE

                //所有图片
                data.picUrls?.let { list ->
                    if (list.isNotEmpty()){
                        mBinding.mImageLL.visibility=View.VISIBLE
                        mBinding.mImageRV.adapter = BatteryImageAdapter(this, list)
                        mBinding.mImageRV.layoutManager = LinearLayoutManager(this)
                    }
                }

//                val preList = ArrayList<String>()
//                val handlerList = ArrayList<String>()
//                val inList = ArrayList<String>()
//                //图片类型 1-预处理 2-拆解毁型 3-入库
//                data2.picUrls?.forEach { b ->
//                    when (b.type) {
//                        1 -> preList.add(b.url.handlerNull())
//                        2 -> handlerList.add(b.url.handlerNull())
//                        3 -> inList.add(b.url.handlerNull())
//                    }
//                }
//                val batterySanList=ArrayList<String>()
//                val batteryHandlerList=ArrayList<String>()
//                val batterySecondList=ArrayList<String>()
//
//                //电池拆解图 片图片类型 1-散件 2-拆解 3-补录
//                data2.pbPicUrls?.forEach { b ->
//                    when (b.type) {
//                        1 -> batterySanList.add(b.url.handlerNull())
//                        2 -> batteryHandlerList.add(b.url.handlerNull())
//                        3 -> batterySecondList.add(b.url.handlerNull())
//                    }
//                }
//
//                if (preList.isNotEmpty()) {
//                    mBinding.mPreTV.visibility = View.VISIBLE
//                    mBinding.mPreRV.adapter = ImageCommonRvV2Adapter(this, preList)
//                    mBinding.mPreRV.layoutManager = GridLayoutManager(this, 3, LinearLayoutManager.VERTICAL, false)
//                }
//                if (handlerList.isNotEmpty()) {
//                    mBinding.mHandlerTV.visibility = View.VISIBLE
//                    mBinding.mHandlerRV.adapter = ImageCommonRvV2Adapter(this, handlerList)
//                    mBinding.mHandlerRV.layoutManager = GridLayoutManager(this, 3, LinearLayoutManager.VERTICAL, false)
//                }
//                if (inList.isNotEmpty()) {
//                    mBinding.mInTV.visibility = View.VISIBLE
//                    mBinding.mInRV.adapter = ImageCommonRvV2Adapter(this, inList)
//                    mBinding.mInRV.layoutManager = GridLayoutManager(this, 3, LinearLayoutManager.VERTICAL, false)
//                }
//                if (batterySanList.isNotEmpty()) {
//                    mBinding.mBatterySanTV.visibility = View.VISIBLE
//                    mBinding.mBatterySanRV.adapter = ImageCommonRvV2Adapter(this, batterySanList)
//                    mBinding.mBatterySanRV.layoutManager = GridLayoutManager(this, 3, LinearLayoutManager.VERTICAL, false)
//                }
//                if (batteryHandlerList.isNotEmpty()) {
//                    mBinding.mBatteryHandlerTV.visibility = View.VISIBLE
//                    mBinding.mBatteryHandlerRV.adapter = ImageCommonRvV2Adapter(this, batteryHandlerList)
//                    mBinding.mBatteryHandlerRV.layoutManager = GridLayoutManager(this, 3, LinearLayoutManager.VERTICAL, false)
//                }
//                if (batterySecondList.isNotEmpty()) {
//                    mBinding.mBatterySecondTV.visibility = View.VISIBLE
//                    mBinding.mBatterySecondRV.adapter = ImageCommonRvV2Adapter(this, batterySecondList)
//                    mBinding.mBatterySecondRV.layoutManager = GridLayoutManager(this, 3, LinearLayoutManager.VERTICAL, false)
//                }


//                if (preList.isEmpty() && handlerList.isEmpty() && inList.isEmpty()&&batterySanList.isEmpty()&&batteryHandlerList.isEmpty()&&batterySecondList.isEmpty()) {
//                    mBinding.mImageLL.visibility = View.GONE
//                }
            }
        })
    }

    override fun click() {

    }

}